#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10, M = 110;

int n, m;
int w[N], dp[N][M][2];

int main()
{
    cin >> n >> m;
    
    for (int i = 1; i <= n; i ++ )
        cin >> w[i];
    
    memset(dp, -0x3f, sizeof dp);
    for(int i = 0; i <= n; i ++ ) dp[i][0][0] = 0;
    
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
        {
            dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1] + w[i]);
            dp[i][j][1] = max(dp[i - 1][j - 1][0] - w[i], dp[i - 1][j][1]);
        }
    
    int res = 0;
    for (int i = 1; i <= m; i ++ ) res = max(res, dp[n][i][0]);
    cout << res;
    return 0;
}
